//package com.lvhx.springboot.rabbitmq;
//
//
//import com.lvhx.springboot.entity.BatchMessage;
//import com.lvhx.springboot.entity.TOrder;
//import com.lvhx.springboot.entity.User;
//import com.lvhx.springboot.mapper.UserMapper;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback;
//import org.springframework.amqp.rabbit.support.CorrelationData;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.UUID;
//
///**
// * 消费方引用的entity必须和发布方包名一致
// */
//
//@Component
//public class RabbitOrderSender {
//
//    //自动注入RabbitTemplate模板类
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//
////    @Autowired
////    private BrokerMessageLogMapper brokerMessageLogMapper;
//
//    @Autowired
//    private UserMapper userMapper;
//
//    //回调函数: confirm确认
//    final ConfirmCallback confirmCallback = new RabbitTemplate.ConfirmCallback() {
//        @Override
//        public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//            System.err.println("correlationData: " + correlationData);
//            String messageIdmessageId = correlationData.getId();
//            if(ack){
//                //如果confirm返回成功 则进行更新
////                brokerMessageLogMapper.changeBrokerMessageLogStatus(messageId, Const.ORDER_SEND_SUCCESS, new Date());
//            } else {
//                //失败则进行具体的后续操作:重试 或者补偿等手段
//                System.err.println("异常处理...");
//            }
//        }
//    };
//
//    //发送消息方法调用: 构建自定义对象消息
//    public void sendOrder(TOrder user) throws Exception {
//        rabbitTemplate.setConfirmCallback(confirmCallback);
//        //消息唯一ID
//        CorrelationData correlationData = new CorrelationData(System.currentTimeMillis() + "$" + UUID.randomUUID().toString());
//        rabbitTemplate.convertAndSend("order-exchange", "order.ABC", user, correlationData);
//    }
//
//    //运行分组批量
//    public void sendBatchMessage(BatchMessage batchMessage) throws Exception {
//        rabbitTemplate.setConfirmCallback(confirmCallback);
//        //消息唯一ID
//        CorrelationData correlationData = new CorrelationData(System.currentTimeMillis() + "$" + UUID.randomUUID().toString());
//        rabbitTemplate.convertAndSend("batch-exchange", "batch.ABC", batchMessage, correlationData);
//    }
//}